package com.example.recyclerdemo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBHelper extends SQLiteOpenHelper {
    public static final String T_STUDENT_NAME = "t_student";
    public static String DB_NAME="student.db";
    public static int DB_VERSION = 1;
    private static final String T_STUDENT= "create table t_student("+
            "id integer primary key autoincrement,"+
            "name varchar(255),"
            +"classmate varchar(255),"
            +"age int);";

    private final static String DROP_T_STUDENT="drop table if exists t_student";

    public DBHelper(@Nullable Context context){
        super(context,DBHelper.DB_NAME,null,DBHelper.DB_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(T_STUDENT);

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
    sqLiteDatabase.execSQL(DROP_T_STUDENT);
    onCreate(sqLiteDatabase);
    }
}
